package com.five.wisdomEat.controller;

import cn.hutool.core.date.DateTime;
import com.five.wisdomEat.entity.Application;
import com.five.wisdomEat.entity.Business;
import com.five.wisdomEat.entity.BusinessInfo;
import com.five.wisdomEat.entity.ResponseMessage;
import com.five.wisdomEat.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/business")
public class BusinessController {
    @Autowired
    private BusinessService service;

    @GetMapping("/getBusinessList")
    public ResponseMessage selectBusinessList(String bNumber){
        return service.selectBusinessList(bNumber);
    }

    @PostMapping("/login")
    public ResponseMessage businessLogin(String bNumber, String password){
        Business business =new Business();
        business.setBNumber(bNumber);
        business.setPassword(password);
        return service.login(business);
    }

    @PostMapping("/register")
    public ResponseMessage businessReg(String bNumber,String bPhone,String bPassword,String bName,String bAddress){
        Business business =new Business();
        business.setBNumber(bNumber);
        business.setPassword(bPassword);
        business.setType("business");
        BusinessInfo businessInfo = new BusinessInfo();
        businessInfo.setBNumber(bNumber);
        businessInfo.setBName(bName);
        businessInfo.setBAddress(bAddress);
        businessInfo.setBPhone(bPhone);
        Application application = new Application();
        application.setABNumber(bNumber);
        application.setATime(new DateTime());
        return service.businessReg(bNumber,bPhone,bPassword,bName,business,businessInfo,application);
    }
}
